'''
Created on Apr 19, 2012

@author: root
'''
from Node import Node
from Disk import Disk
from Log import Log
from User import User
from XML_File import XML_File
from Java import  Java
from NodeCheck import NodeCheck
from Software import Software
from Filesystem import Filesystem

if __name__ == '__main__':
    Roles = []
    Nodes = []
    Users = []
     
     
    adminUser = "root"
    adminPW  = "P@ssw0rd"
    for i in range (1,5,1):
        node = Node("hadoop0"+str(i),"10.10.88.245","*njd")
        disk1 = Disk("/dev/sdb",False,"xfs",0,0)
        disk2 = Disk("/dev/sdc",False,"xfs",0,0)
        disk3 = Disk("/dev/sdd",False,"xfs",0,0)
        disk4 = Disk("/dev/sde",False,"xfs",0,0)
        node.add_Disk(disk1)
        node.add_Disk(disk2)
        node.add_Disk(disk3)
        node.add_Disk(disk4)
        node.set_adminUser(adminUser)
        node.set_adminPW(adminPW)
        Nodes.append(node)
  
    Logs = Log()
    

         
    Users.append(User("root","P@ssw0rd","r","Adminstrative User"))
    for node in Nodes:
        for disk in node.get_Disks():
            print str(node.get_hostName())+":"+str(disk.get_deviceName()+":"+str(disk.get_fsStatus()))
    
    fs = Filesystem(Nodes,Users,Logs)
    fsStatus = fsInstallStatus = fs.install()
    fs.mount("/HadoopData", "/disk")

    for fslog in Logs.get_Log_FS():
        print fslog.get()
        
    for node in Nodes:
        for disk in node.get_Disks():
            print str(node.get_hostName())+":"+str(disk.get_deviceName()+":"+str(disk.get_fsStatus()))
    
    sw = Software("/tmp",Logs,Nodes,Users)

    sw.pushRPMS()   
    sw.installRPMs()

    nc = NodeCheck(Logs,Nodes,Users)
    nc.inventory()

    for log in Logs.get_Log_NodeCheck():
        print log.get()
    
    for node in Nodes:
        print node.get_total_rawCapacity()
        
    
    coreSite = XML_File("./conf/gold/","mapred-site.xml",Logs,Nodes,Users)
    coreSite.diff()
    
    print coreSite.getProperties()
    coreSite.modify("mapred.tasktracker.reduce.tasks.maximum", "2")
    print coreSite.getProperties()
    coreSite.push()
    for log in Logs.get_Log_XML():
        print log.get()
    java = Java(Logs,Nodes,Users)
    java.checkJDK()
    java.removeOpenJDK()
    #java.pushJDK("/tmp/jdk-7u2-linux-x64.rpm","/tmp/jdk-7u2-linux-x64.rpm")
    java.installJDK("/tmp/jdk-7u2-linux-x64.rpm")
    java.checkJDK()

    for log in Logs.get_Log_Java():
        print log.get()
       
    
    